package com.gzist.elderlyserviceplatform.controller.admin;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gzist.elderlyserviceplatform.common.Result;
import com.gzist.elderlyserviceplatform.entity.dto.ServiceReservationQueryDTO;
import com.gzist.elderlyserviceplatform.entity.dto.ServiceReservationReviewDTO;
import com.gzist.elderlyserviceplatform.entity.po.ServiceReservation;
import com.gzist.elderlyserviceplatform.entity.vo.HomePageInfoCountVOO;
import com.gzist.elderlyserviceplatform.entity.vo.ServiceReservationVO;
import com.gzist.elderlyserviceplatform.service.ServiceReservationService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 服务预约表
 */
@RestController
@Tag(name = "服务预约管理")
@RequestMapping("/api/admin/serviceReservation")
@RequiredArgsConstructor
public class ServiceReservationControllerA {

    private final ServiceReservationService serviceReservationService;

    /**
     * 服务预约列表查询
     */
    @PostMapping("/list")
    @Operation(summary = "查询服务预约列表", description = "分页过滤查询服务预约列表，支持模糊查询服务名称和预约人名称，精确查询审核状态")
    public Result<Page<ServiceReservationVO>> listServiceReservations(
            @RequestBody
            @Parameter(description = "查询参数") ServiceReservationQueryDTO queryDTO
    ) {
        return Result.success(serviceReservationService.queryPage(queryDTO),"查询成功!");
    }

    /**
     * 审核服务预约
     */
    @PostMapping("/review")
    @Operation(summary = "审核服务预约", description = "根据预约id进行审核服务预约")
    public Result<String> reviewServiceReservation(
            @RequestBody
            @Parameter(description = "审核参数") ServiceReservationReviewDTO reviewDTO
    ) {
        serviceReservationService.reviewServiceReservation(reviewDTO);
        return Result.success("审核成功");
    }

    /**
     * 查询单个服务预约详情
     */
    @GetMapping("/detail/{id}")
    @Operation(summary = "查询单个服务预约详情", description = "根据id查询服务预约详情")
    public Result<ServiceReservation> getServiceReservation(
            @PathVariable
            @Parameter(description = "服务预约id") String id
    ) {
        return Result.success(serviceReservationService.getById(id), "查询成功");
    }

    /**
     * 查询各个服务以及其预约人数接口
     */
    @GetMapping("/count")
    @Operation(summary = "查询各个服务以及其预约人数接口", description = "查询各个服务以及其预约人数接口")
    public Result<List<HomePageInfoCountVOO>> countServiceReservation(){
        List<HomePageInfoCountVOO> array = serviceReservationService.countServiceReservation();
        return Result.success(array, "查询成功");
    }

    /**
     * 删除服务预约
     */
    @PostMapping("/delete/{id}")
    @Operation(summary = "删除服务预约", description = "根据id删除服务预约")
    public Result deleteServiceReservation(
            @PathVariable
            @Parameter(description = "服务预约id") String id
    ) {
        serviceReservationService.removeById(id);
        return Result.success("删除成功");
    }

    @PostMapping("/batchDelete")
    @Operation(summary = "批量删除服务预约", description = "根据id批量删除服务预约")
    public Result deleteBatchServiceReservation(
            @RequestBody
            @Parameter(description = "服务预约id集") String[] ids
    ) {
        serviceReservationService.removeByIds(Arrays.asList(ids));
        return Result.success("删除成功");
    }
}